#ifndef NMC_IMAGELOADER_HPP
#define NMC_IMAGELOADER_HPP

#include "image.hpp"
#include "guichan/opengl/openglsdlimageloader.hpp"

namespace nmc
{
	class ImageLoader: public gcn::SDLImageLoader
	{
		virtual gcn::Image* load(const std::string& filename,
                                 bool convertToDisplayFormat = true)
        {
            SDL_Surface *loadedSurface = loadSDLSurface(filename);

            if (loadedSurface == NULL)
            {
                throw GCN_EXCEPTION(
                        std::string("Unable to load image file: ") + filename);
            }

            SDL_Surface *surface = convertToStandardFormat(loadedSurface);
            SDL_FreeSurface(loadedSurface);

            if (surface == NULL)
            {
                throw GCN_EXCEPTION(
                        std::string("Not enough memory to load: ") + filename);
            }

            Image *image = new Image((unsigned int*)surface->pixels,
                                      surface->w,
                                      surface->h,
                                      convertToDisplayFormat);
            SDL_FreeSurface(surface);

            return image;
        }
	};
}

#endif